/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package agents.interfaceagent;

import BESA.Kernell.Agent.Event.DataBESA;
import BESA.Kernell.System.Directory.AgHandlerBESA;
import co.edu.javeriana.ayllu.agents.interfaceagentagent.InterfaceAgentState;
import co.edu.javeriana.ayllu.data.Ayllu_Data_Message;
import co.edu.javeriana.ayllu.data.Ayllu_WallMessageData;
import gui.ChatGUI;

/**
 * The state of the SynchIA interface, it contains the CA that invoked it
 * @author Ayllu
 */
public class IA_SynchCommInterfaceState extends InterfaceAgentState {

    private AgHandlerBESA catoreply = null;
    private ChatGUI theGUI = null;
   

    public IA_SynchCommInterfaceState(AgHandlerBESA sessionManagerHandler) {
        super(sessionManagerHandler);
    }

    public AgHandlerBESA getCatoreply() {
        return catoreply;
    }

    public void setCatoreply(AgHandlerBESA catoreply) {
        this.catoreply = catoreply;
    }

    @Override
    public void handleSMRequest(DataBESA theData) {
        if (theData instanceof Ayllu_WallMessageData) {
            Ayllu_WallMessageData data = (Ayllu_WallMessageData) theData;
            String userName = (data.getSenderName().equals(theGUI.getName()) ? "Yo" : data.getSenderName());
            String message = userName + ": " + String.valueOf(data.getMessage());
            theGUI.updateMessageQueue(message);
        }else if(theData instanceof Ayllu_Data_Message){
            String message = (String) ((Ayllu_Data_Message)theData).getMessage();
            theGUI.updateMessageQueue(message);
        }
    }

    @Override
    public void handleAARequest(DataBESA theData) {

    }

    @Override
    public void handleRAQuestion(DataBESA theData) {

    }

    public void setTheGUI(ChatGUI theGUI) {
        this.theGUI = theGUI;
    }
    
}
